import { request } from '../utils'

export async function login (params) {
  return request('/api/login', {
    method: 'post',
    data: params
  })
}

export async function logout (params) {
  return request('/api/logout', {
    method: 'post',
    data: params
  })
}

export async function userInfo (params) {
  return request('/api/userInfo', {
    method: 'get',
    data: params
  })
}
export  async function fetchUser() {
    const token = window.localStorage.getItem('tmdToken');
    return request('/api/login', {
        method: 'POST',
        headers: new Headers({
            "Authorization": `Bearer ${token}`
        })
    });
}
export async function auth(payload) {
    return request('/api/login', {
        method: 'POST',
        headers: new Headers({
            "Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
        }),
        body: stringify({
            ...payload,
            grant_type: 'password'
        })
    });
}